package com.rui.study.commons.study.support.validate;

import com.rui.study.commons.study.model.dto.AccountDTO;
import com.rui.study.commons.study.support.validate.annotation.NotBothEmpty;
import com.rui.study.commons.util.StringUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class AuthValidator implements ConstraintValidator<NotBothEmpty, AccountDTO> {

    @Override
    public void initialize(NotBothEmpty constraintAnnotation) {

    }

    @Override
    public boolean isValid(AccountDTO accountDTO, ConstraintValidatorContext constraintValidatorContext) {
        String verifyCode  = accountDTO.getVerifyCode();
        String password = accountDTO.getPassword();
        return !StringUtil.isEmpty(verifyCode) || !StringUtil.isEmpty(password);
    }
}
